//
//  HNSH_ChatOpenRedDetailHeader.m
//  NongYe
//
//  Created by 李宇廷 on 2023/2/6.
//

#import "HNSH_ChatOpenRedDetailHeader.h"

@interface HNSH_ChatOpenRedDetailHeader ()

/* headerImgV */
@property (nonatomic, strong) UIImageView *headerImgV;
/* nameLabel */
@property (nonatomic, strong) UILabel *nameLabel;
/* iconImgV */
@property (nonatomic, strong) UIImageView *iconImgV;
/* desLabel */
@property (nonatomic, strong) UILabel *desLabel;
/* moneyLabel */
@property (nonatomic, strong) UILabel *moneyLabel;

/* redCountLabel */
@property (nonatomic, strong) UILabel *redCountLabel;
/* lineView */
@property (nonatomic, strong) UIView *lineView;
/* bottomLine */
@property (nonatomic, strong) UIView *bottomLine;

@end

@implementation HNSH_ChatOpenRedDetailHeader

- (instancetype)initWithFrame:(CGRect)frame {
    self = [super initWithFrame:frame];
    if (self) {
        self.backgroundColor = [UIColor whiteColor];
        [self configUI];
    }
    return self;
}

- (void)configUI {
    [self addAllViews];
    [self addAllLayout];
}

- (void)setDetailInfo:(HNSH_ChatRedDetailInfoModel *)detailInfo {
    _detailInfo = detailInfo;
    self.nameLabel.text = detailInfo.nickname;
    [self.headerImgV sd_setImageWithURL:[NSURL URLWithString:detailInfo.avatar_url] placeholderImage:[UIImage imageNamed:@"login_home_center_icon"]];
    self.desLabel.text = detailInfo.title;
    
    self.moneyLabel.text = [NSString stringWithFormat:@"%.2f 绿色能量",[detailInfo.open_amount doubleValue]];
    self.moneyLabel.attributedText = [ST_AttributeLabelTool handleLabelWithContent:self.moneyLabel.text SelectContent:@"绿色能量" CommonFont:self.moneyLabel.font SpeFont:[UIFont systemFontOfSize:16] Color:self.moneyLabel.textColor];
    
    self.redCountLabel.text = detailInfo.open_desc;
}

- (void)addAllViews {
    self.backgroundColor = [UIColor whiteColor];
    
    [self addSubview:self.nameLabel];
    [self addSubview:self.headerImgV];
    [self addSubview:self.iconImgV];
    
    [self addSubview:self.desLabel];
    [self addSubview:self.moneyLabel];
    
    [self addSubview:self.lineView];
    [self addSubview:self.redCountLabel];
    [self addSubview:self.bottomLine];
    
    
}

- (void)addAllLayout {
    [self.nameLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerX.equalTo(self.mas_centerX);
        make.top.mas_equalTo(28);
        make.height.mas_equalTo(25);
    }];
    [self.headerImgV mas_makeConstraints:^(MASConstraintMaker *make) {
        make.right.equalTo(self.nameLabel.mas_left).offset(-4);
        make.centerY.equalTo(self.nameLabel.mas_centerY);
        make.width.height.mas_equalTo(24);
    }];
    [self.iconImgV mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(self.nameLabel.mas_right).offset(4);
        make.centerY.equalTo(self.nameLabel.mas_centerY);
        make.width.height.mas_equalTo(20);
    }];
    
    [self.desLabel setContentHuggingPriority:UILayoutPriorityRequired forAxis:UILayoutConstraintAxisVertical];
    [self.desLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(self.nameLabel.mas_bottom).offset(10);
        make.left.mas_equalTo(30);
        make.right.mas_equalTo(-30);
    }];
    [self.moneyLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(self.desLabel.mas_bottom).offset(20);
        make.centerX.equalTo(self.mas_centerX);
        make.height.mas_equalTo(50);
    }];
    
    [self.lineView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.right.mas_equalTo(0);
        make.bottom.mas_equalTo(-44);
        make.height.mas_equalTo(8);
    }];
    [self.redCountLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.mas_equalTo(17);
        make.bottom.mas_equalTo(-12);
        make.height.mas_equalTo(20);
    }];
    [self.bottomLine mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.right.mas_equalTo(0);
        make.bottom.mas_equalTo(0);
        make.height.mas_equalTo(1);
    }];
}

#pragma mark lazy
- (UIImageView *)headerImgV {
    if (!_headerImgV) {
        _headerImgV = [[UIImageView alloc]init];
        _headerImgV.backgroundColor = [UIColor orangeColor];
        _headerImgV.layer.cornerRadius = 4.0f;
        _headerImgV.layer.masksToBounds = YES;
    }
    return _headerImgV;
}

- (UILabel *)nameLabel {
    if (!_nameLabel) {
        _nameLabel = [[UILabel alloc]init];
        _nameLabel.text = @"";
        _nameLabel.textColor = [UIColor colorWithHexString:@"#333333"];
        _nameLabel.font = [UIFont boldSystemFontOfSize:18];
    }
    return _nameLabel;
}

- (UIImageView *)iconImgV {
    if (!_iconImgV) {
        _iconImgV = [[UIImageView alloc]initWithImage:[UIImage imageNamed:@"chat_open_red_detail_icon"]];
    }
    return _iconImgV;
}

- (UILabel *)desLabel {
    if (!_desLabel) {
        _desLabel = [[UILabel alloc]init];
        _desLabel.text = @"";
        _desLabel.textColor = [UIColor colorWithHexString:@"#999999"];
        _desLabel.font = [UIFont systemFontOfSize:14];
        _desLabel.numberOfLines = 0;
        _desLabel.textAlignment = NSTextAlignmentCenter;
    }
    return _desLabel;
}


- (UILabel *)moneyLabel {
    if (!_moneyLabel) {
        _moneyLabel = [[UILabel alloc]init];
        _moneyLabel.textColor = [UIColor colorWithHexString:@"#DF7302"];
        _moneyLabel.font = [UIFont boldSystemFontOfSize:36];
    }
    return _moneyLabel;
}

- (UIView *)lineView {
    if (!_lineView ) {
        _lineView = [[UIView alloc]init];
        _lineView.backgroundColor = [UIColor colorWithHexString:@"#F7F7F7"];
    }
    return _lineView;
}

- (UILabel *)redCountLabel {
    if (!_redCountLabel) {
        _redCountLabel = [[UILabel alloc]init];
        _redCountLabel.text = @"";
        _redCountLabel.textColor = [UIColor colorWithHexString:@"#999999"];
        _redCountLabel.font = [UIFont systemFontOfSize:14];
    }
    return _redCountLabel;
}

- (UIView *)bottomLine {
    if (!_bottomLine ) {
        _bottomLine = [[UIView alloc]init];
        _bottomLine.backgroundColor = [UIColor colorWithHexString:@"#F3F3F3"];
    }
    return _bottomLine;
}


/*
// Only override drawRect: if you perform custom drawing.
// An empty implementation adversely affects performance during animation.
- (void)drawRect:(CGRect)rect {
    // Drawing code
}
*/

@end
